package com.letian.record.service.impl;

import java.util.List;
import com.letian.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.letian.record.mapper.RecordTaskMapper;
import com.letian.record.domain.RecordTask;
import com.letian.record.service.IRecordTaskService;

/**
 * 记录任务Service业务层处理
 * 
 * @author bmz
 * @date 2023-09-28
 */
@Service
public class RecordTaskServiceImpl implements IRecordTaskService 
{
    @Autowired
    private RecordTaskMapper recordTaskMapper;

    /**
     * 查询记录任务
     * 
     * @param taskId 记录任务主键
     * @return 记录任务
     */
    @Override
    public RecordTask selectRecordTaskByTaskId(Long taskId)
    {
        return recordTaskMapper.selectRecordTaskByTaskId(taskId);
    }

    /**
     * 查询记录任务列表
     * 
     * @param recordTask 记录任务
     * @return 记录任务
     */
    @Override
    public List<RecordTask> selectRecordTaskList(RecordTask recordTask)
    {
        return recordTaskMapper.selectRecordTaskList(recordTask);
    }

    /**
     * 新增记录任务
     * 
     * @param recordTask 记录任务
     * @return 结果
     */
    @Override
    public int insertRecordTask(RecordTask recordTask)
    {
        recordTask.setCreateTime(DateUtils.getNowDate());
        return recordTaskMapper.insertRecordTask(recordTask);
    }

    /**
     * 修改记录任务
     * 
     * @param recordTask 记录任务
     * @return 结果
     */
    @Override
    public int updateRecordTask(RecordTask recordTask)
    {
        recordTask.setUpdateTime(DateUtils.getNowDate());
        Long count = recordTask.getUpdateCount() == null ? 1 : recordTask.getUpdateCount() + 1;
        recordTask.setUpdateCount(count);
        return recordTaskMapper.updateRecordTask(recordTask);
    }


    public int disableOrEnableTask(Long taskId,String updateBy){
        RecordTask task = recordTaskMapper.selectRecordTaskByTaskId(taskId);
        if(task == null){
            return 0;
        }
        if("1".equals(task.getDelFlag())){
            task.setDelFlag("0");
        }else{
            task.setDelFlag("1");
        }
        task.setUpdateBy(updateBy);
        task.setUpdateTime(DateUtils.getNowDate());
        return recordTaskMapper.updateRecordTask(task);
    }

    /**
     * 批量删除记录任务
     * 
     * @param taskIds 需要删除的记录任务主键
     * @return 结果
     */
    @Override
    public int deleteRecordTaskByTaskIds(Long[] taskIds)
    {
        return recordTaskMapper.deleteRecordTaskByTaskIds(taskIds);
    }

    /**
     * 删除记录任务信息
     * 
     * @param taskId 记录任务主键
     * @return 结果
     */
    @Override
    public int deleteRecordTaskByTaskId(Long taskId)
    {
        return recordTaskMapper.deleteRecordTaskByTaskId(taskId);
    }
}
